﻿Public Class ClsIndustryAccountTypeDbAccess
    'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\自写系统\rjcwxt\Rjcwxt\data\sys.mdb;Persist Security Info=True
    Private mConnectionString As String '数据库连接字符串
    Private mAppTableName As String 'S_IndustryAcctountType在库中的表名 S_App

    Public Sub New(ByVal connString As String)
        mConnectionString = connString
    End Sub

    Public Sub New(ByVal connString As String, ByVal tableName As String)
        mConnectionString = connString
        mAppTableName = tableName

    End Sub

    Public Property ConnectionString As String
        Get
            Return mConnectionString
        End Get
        Set(value As String)
            mConnectionString = value
        End Set
    End Property

    Public Property AppTableName As String
        Get
            Return mAppTableName
        End Get
        Set(value As String)
            mAppTableName = value
        End Set
    End Property

    Public Function GetIndustryAccountTypeById(ByVal industryId As Int16) As ClsIndustryAccountType
        Try

            Dim tmpSql As String
            Dim tmpDbAccess = New ClsDbAccessMdb(mConnectionString)
            Dim tmpList As List(Of ClsIndustryAccountType)
            '打开数据库
            tmpDbAccess.DbOpen()
            '构造查询语句
            tmpSql = "select * from [" & TABLE_NAME_INDUSTRY_ACCOUNT_TYPE & "] Where [IndustryId]= " & industryId

            '查询并将返回数据解析为List对象
            tmpList = ConvertRecordToClass(tmpDbAccess.ExecuteSqlReturnDataSet(tmpSql))

            '关闭数据库
            tmpDbAccess.DbClose()

            Return tmpList(0)

        Catch ex As OleDb.OleDbException

            mErrorNumber = ex.ErrorCode
            mErrorMessage = ex.Message
            mErrorCreater = "ClsIndustryAccountTypeDbAccess - GetAllIndustryAcctountType"

            Return Nothing
        End Try
    End Function

    Public Function GetAllIndustryAccountType() As List(Of ClsIndustryAccountType)
        Try

            Dim tmpSql As String
            Dim tmpDbAccess = New ClsDbAccessMdb(mConnectionString)
            Dim tmpList As List(Of ClsIndustryAccountType)
            '打开数据库
            tmpDbAccess.DbOpen()
            '构造查询语句
            tmpSql = "select * from [" & TABLE_NAME_INDUSTRY_ACCOUNT_TYPE & "] Order by [IndustryId]"

            '查询并将返回数据解析为List对象
            tmpList = ConvertRecordToClass(tmpDbAccess.ExecuteSqlReturnDataSet(tmpSql))

            '关闭数据库
            tmpDbAccess.DbClose()

            Return tmpList

        Catch ex As OleDb.OleDbException

            mErrorNumber = ex.ErrorCode
            mErrorMessage = ex.Message
            mErrorCreater = "ClsIndustryAccountTypeDbAccess - GetAllIndustryAcctountType"

            Return Nothing
        End Try
    End Function

    Public Function ConvertRecordToClass(tmpDataReader As OleDb.OleDbDataReader) As List(Of ClsIndustryAccountType)

        If tmpDataReader Is Nothing Then
            Return Nothing
        End If
        Try

            Dim tmpList As List(Of ClsIndustryAccountType) = New List(Of ClsIndustryAccountType)
            Dim tmpCls As ClsIndustryAccountType

            While tmpDataReader.Read()

                tmpCls = New ClsIndustryAccountType()
                'IndustryId,Industry,NewAcctLength,OneLevelAcctLength,
                'CashCode, , ,
                ',,,,,,
                With tmpCls
                    .IndustryId = tmpDataReader.GetInt16(0)
                    .Industry = ConvertDbNullString(tmpDataReader(1)) '.GetString(1)
                    .NewAcctLength = tmpDataReader.GetInt16(2)
                    .OneLevelAcctLength = tmpDataReader.GetInt16(3)
                    .CashCode = ConvertDbNullString(tmpDataReader(4)) 'tmpDataReader.GetString(4)
                    .BankCode = ConvertDbNullString(tmpDataReader(5)) ' tmpDataReader.GetString(5)
                    .AssetsCode = ConvertDbNullString(tmpDataReader(6)) ' tmpDataReader.GetString(6)
                    .DepCode = ConvertDbNullString(tmpDataReader(7)) ' tmpDataReader.GetString(7)
                    .RecieveCode = ConvertDbNullString(tmpDataReader(8)) 'tmpDataReader.GetString(8)
                    .PayCode = ConvertDbNullString(tmpDataReader(9)) ' tmpDataReader.GetString(9)
                    .GainCode = ConvertDbNullString(tmpDataReader(10)) 'tmpDataReader.GetString(10)
                    .IncAndDecCode = ConvertDbNullString(tmpDataReader(11)) 'tmpDataReader.GetString(11)
                    .StockCode = ConvertDbNullString(tmpDataReader(12)) ' tmpDataReader.GetString(12)
                    .DevCode = ConvertDbNullString(tmpDataReader(13)) 'tmpDataReader.GetString(13)

                End With

                tmpList.Add(tmpCls)

            End While

            Return tmpList

        Catch ex As OleDb.OleDbException

            mErrorNumber = ex.ErrorCode
            mErrorMessage = ex.Message
            mErrorCreater = "ClsIndustryAccountTypeDbAccess - ConvertRecordToClass"

            Return Nothing
        End Try
    End Function

End Class
